/*
 * FoodGenerator.java
 *
 * Created on January 11, 2007, 12:57 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.sf.iSnake.core;

import net.sf.iSnake.configuration.iSnakeConfiguration;

/**
 *
 * @author thelinuxmaniac
 */
public class FoodGenerator {
    
    private RandomNumberGenerator randomNumberGeneratorX;
    private RandomNumberGenerator randomNumberGeneratorY;
    
    private GameAreaCoordinate currentFoodCoordinate;
    private GameAreaCoordinate nextFoodCoordinate;
    
    private iSnakeConfiguration conf;
    
    /**
     * Initialized the random number generators for the X and Y coordinates
     * stores a local copy of iSnakeConfiguration object
     */
    public FoodGenerator(iSnakeConfiguration conf) {
        this.conf = conf;
        // Note: Width stands for X coordinate. Height stands for Y coordinate
        randomNumberGeneratorX = new RandomNumberGenerator(8,0,conf.GAME_AREA_WIDTH.intValue());
        randomNumberGeneratorY = new RandomNumberGenerator(8,0,conf.GAME_AREA_HEIGHT.intValue());
        
        currentFoodCoordinate.setX(randomNumberGeneratorX.getRandomNumber().shortValue());
        currentFoodCoordinate.setY(randomNumberGeneratorY.getRandomNumber().shortValue());
    }
    
    /**
     * Returns the current food coordinates. IT DOES NOT SET THE VALUE OF currentFood or nextFood.
     * @return GameAreaCoordinate object containing the position of current food in the game
     */
    public GameAreaCoordinate getCurrentFoodCoordinate()
    {
        return currentFoodCoordinate;
    }
    
    /**
     * Returns the next food coordinates. IT DOES NOT SET THE VALUE OF currentFood or nextFood.
     * @return GameAreaCoordinate object containing the position of next food in the game
     */
    public GameAreaCoordinate getNextFoodCoordinate()
    {
        return nextFoodCoordinate;
    }
    
    /**
     * It stores the value of nextFood into currentFood and Generates a new random coordinates for next food
     * NOTE: IT ONLY GENERATES THE NEW VALUE OF NEXT FOOD AND STORE IT IN A GameAreaCoordinate object
     */
    public void generateNewFoodCoordinate()
    {
        currentFoodCoordinate = nextFoodCoordinate;

        nextFoodCoordinate.setX(randomNumberGeneratorX.getRandomNumber().shortValue());
        nextFoodCoordinate.setY(randomNumberGeneratorY.getRandomNumber().shortValue());
    }
    
    /**
     * It executes the generateNewFoodCoordinate() method and returns the new value of currentFood
     * @return The newly set value of current food
     */
    public GameAreaCoordinate getNewFoodCoordinate()
    {
        generateNewFoodCoordinate();
        return currentFoodCoordinate;
    }
}
